package com.webbei.Backstage.action;

import java.io.File;
import java.io.IOException;

import org.apache.struts2.ServletActionContext;

import com.webbei.Backstage.service.BackstateSer;

public class DeleteAdvertismentImageAction {
	private BackstateSer bao;
	private int imageId;
	private String imageName;
	public String execute(){
		System.out.println(imageId+"--"+imageName);
		int i=bao.deleteAdvertismentById(imageId);
		if(i==1){
			String path=ServletActionContext.getServletContext().getRealPath("/");
			System.out.println(path+"img/advertismentImage/"+imageName);
			File f=new File(path+"/img/advertismentImage/"+imageName);
			f.delete();
			try {
				ServletActionContext.getResponse().getWriter().write("success");
				ServletActionContext.getResponse().setContentType("text/html");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if(i==0){
			try {
				ServletActionContext.getResponse().getWriter().write("fail");
				ServletActionContext.getResponse().setContentType("text/html");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
	public BackstateSer getBao() {
		return bao;
	}
	public void setBao(BackstateSer bao) {
		this.bao = bao;
	}
	public int getImageId() {
		return imageId;
	}
	public void setImageId(int imageId) {
		this.imageId = imageId;
	}
	public String getImageName() {
		return imageName;
	}
	public void setImageName(String imageName) {
		this.imageName = imageName;
	}
	
}
